<template>
  <div>
    <Chart v-if="show==true" :cdata="cdata" />
  </div>
</template>

<script>
import {stasticAlarmByMonth} from '@/api/business/alarm/alarmlog'
import Chart from './chart.vue'
export default {
  data () {
    return {
      show:false,
      cdata: {
        category: [

        ],
        lineData: [
        
        ],
        barData: [
         
        ],
        rateData: []
      }
    };
  },
  components: {
    Chart,
  },
  created(){
this.initAlarmnum();
  },
  mounted () {
    this.setData();
  },
  methods: {

      //初始化柱状图数据
        async initAlarmnum(){
        const res = await stasticAlarmByMonth();
        for(var i=0;i<res.data.length;i++){
        this.cdata.barData[i]=res.data[i].num
        this.cdata.lineData[i]=res.data[i].num
        this.cdata.category[i]=res.data[i].mouth
    }
            this.show = true
        },

    // 根据自己的业务情况修改
    setData () {
      for (let i = 0; i < this.cdata.barData.length -1; i++) {
        let rate = this.cdata.barData[i] / this.cdata.lineData[i];
        this.cdata.rateData.push(rate.toFixed(2));
      }
    },
  }
};
</script>

<style lang="scss" scoped>
</style>